package com.bt.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bt.annotation.RequiresPermissionsDesc;
import com.bt.pojo.DtsComment;
import com.bt.service.DtsCommentSerive;
import com.bt.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wbt
 * @version v1.0
 * @project shop_manage
 * @data 2022/9/24 11:25
 **/

@RestController
@RequestMapping("/admin/comment")
@CrossOrigin
public class AdminCommentController {
    @Autowired
    private DtsCommentSerive dtsCommentSeriveImpl;
    /**
     * http://localhost:8080/admin/comment/list?page=1&limit=20&userId=22&valueId=11&sort=add_time&order=desc
     * get 查询评论列表
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:comment:list")
    @RequiresPermissionsDesc(menu = {"系统管理", "商品管理"}, button = "查询评论")
    public Object list(Integer page,Integer limit,Integer userId,Integer valueId,String sort,String order){
        if (page==null||page<1) {page=1;}
        if (limit==null||limit<1) {limit=20;}
        IPage<DtsComment> IPage=dtsCommentSeriveImpl.findCommentByPage(page,limit,userId,valueId,sort,order);
        Map data=new HashMap();
        data.put("total",IPage.getTotal());
        data.put("items",IPage.getRecords());
        return ResponseUtil.ok(data);
    }
    /**
     * http://localhost:8080/admin/comment/delete
     * post
     */
    @PostMapping("/delete")
    @RequiresPermissions("admin:comment:delete")
    @RequiresPermissionsDesc(menu = {"系统管理", "商品管理"}, button = "删除评论")
    public Object delete(@RequestBody DtsComment dtsComment){
        try {
            dtsCommentSeriveImpl.deleteComment(dtsComment);
            return ResponseUtil.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseUtil.fail(999, e.getMessage());
        }
    }

}
